package com.jake.sort;

import com.jake.sort.vo.Person;
import org.junit.Before;
import org.junit.Test;

import java.util.Comparator;
import java.util.List;

public class ListSort {

    private List<Person> persons;

    @Before
    public void initPersons() {
        Person p1 = new Person();
        p1.setAge(20);
        p1.setHeight(176);

        Person p2 = new Person();
        p2.setAge(16);
        p2.setHeight(180);

        Person p3 = new Person();
        p3.setAge(25);
        p3.setHeight(168);

        persons.add(p1);
        persons.add(p2);
        persons.add(p3);

        System.out.println("排序前" + persons);
    }

    @Test
    public void sortByFields() {
        persons.sort(Comparator.comparing(Person::getAge).thenComparing(Person::getHeight));
    }
}
